package com.core.util;

import java.io.Serializable;
import java.util.List;

public class Pagination<T> implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -745181188870408462L;

	private List<T> rows; // 数据

	private long total; // 总记录数

	private long page; // 当前页
	
	private long rowCount; //每页显示记录
	
	private StringBuffer pagina; //翻页控件
	
	private List<T> footer;//汇总数据
	
	public Pagination(List<T> rows, long totalCount , long rowCount) {
		this.rows = rows;
		this.total = totalCount;
		this.rowCount = rowCount;
	}
	
	/**
	 * @return the pagina
	 * <div style="float:right;font-family:Tahoma" id="uid_div3">第一页&nbsp;|&nbsp;上一页&nbsp;|&nbsp;<a onclick="DataGrid.nextPage('dg1');" href="javascript:void(0);">下一页</a>&nbsp;|&nbsp;<a onclick="DataGrid.lastPage('dg1');" href="javascript:void(0);">最末页</a>&nbsp;&nbsp;转到第&nbsp;<input type="text" onkeyup="value=value.replace(/\D/g,'')" style="width:40px" class="inputText" id="_PageBar_Index">&nbsp;页&nbsp;&nbsp;<input type="button" value="跳转" class="inputButton" onclick="if(!/^\d+$/.test($V('_PageBar_Index'))||$V('_PageBar_Index')&lt;1||$V('_PageBar_Index')&gt;2){alert('错误的页码');$('_PageBar_Index').focus();}else{var pageIndex = ($V('_PageBar_Index')-1)&gt;0?$V('_PageBar_Index')-1:0;DataGrid.setParam('dg1','_ZVING_PAGEINDEX',pageIndex);DataGrid.loadData('dg1');}" id="uid_input5"></div>
	 * <div style="float:left;font-family:Tahoma" id="uid_div4">共 28 条记录，每页 15 条，当前第 1 / 2 页</div>
	 */
	public StringBuffer getPagina() {
		return null;
		/**
		this.pagina = new StringBuffer(200);
		this.pagina.append("<div style='float:right;font-family:Tahoma'>");
		//第一页
		if (page == 1){
			this.pagina.append("第一页&nbsp;");
			this.pagina.append("|");
			this.pagina.append("上一页&nbsp;");
		} else {
			this.pagina.append("<a onclick=\"DSP.changePage('?page=1&rp="+rowCount+"');\" href='javascript:void(0)'>第一页</a>");
			this.pagina.append("|");
			this.pagina.append("<a onclick=\"DSP.changePage('?page="+(page-1)+"&rp="+rowCount+"');\" href='javascript:void(0)'>上一页</a>");
		}
		this.pagina.append("|");
		//跳转页
		//this.pagina.append("&nbsp;转到第&nbsp;<input type=\"text\" onkeyup=\"value=value.replace(/\\D/g,'')\" style=\"width:40px\" class=\"inputText\">&nbsp;页&nbsp;&nbsp;");
		//this.pagina.append("|");
		//最末页
		long next = total / rowCount + 1;
		if (page < next){
			this.pagina.append("<a onclick=\"DSP.changePage('?page="+(page+1)+"&rp="+rowCount+"');\" href='javascript:void(0)'>下一页</a>");
			this.pagina.append("|");
			this.pagina.append("<a onclick=\"DSP.changePage('?page="+(next)+"&rp="+rowCount+"');\" href='javascript:void(0)'>最末页</a>");
		} else {
			this.pagina.append("下一页&nbsp;");
			this.pagina.append("|");
			this.pagina.append("最末页&nbsp;");
		}
		this.pagina.append("</div>");
		//
		this.pagina.append("<div style='float:left;font-family:Tahoma'>共&nbsp;")
		.append(this.total)
		.append("&nbsp;条记录，每页")
		.append(this.rowCount).append("&nbsp;条,当前第&nbsp;").append(page).append("&nbsp;/&nbsp;").append(next).append("&nbsp;页</div>");
		return pagina;
		*/
	}



	/**
	 * @param pagina the pagina to set
	 */
	public void setPagina(StringBuffer pagina) {
		this.pagina = pagina;
	}



	/**
	 * @return the list
	 */
	public List<T> getRows() {
		return rows;
	}

	/**
	 * @return the total
	 */
	public long getTotal() {
		return total;
	}

	/**
	 * @return the page
	 */
	public long getPage() {
		return page;
	}

	/**
	 * @param list
	 *            the list to set
	 */
	public void setRows(List<T> rows) {
		this.rows = rows;
	}

	/**
	 * @param total
	 *            the total to set
	 */
	public void setTotal(long total) {
		this.total = total;
	}

	/**
	 * @param page
	 *            the page to set
	 */
	public void setPage(long page) {
		this.page = page;
	}

	/**
	 * @return the footer
	 */
	public List<T> getFooter() {
		return footer;
	}

	/**
	 * @param footer the footer to set
	 */
	public void setFooter(List<T> footer) {
		this.footer = footer;
	}
}
